﻿var express = require('express')
var app = express()
var bodyParser = require('body-parser')
var compress = require('compression')
var cookieParser = require("cookie-parser")
var admin = require('./routes/admin.js')
const log = require('./logger')
var logger = require('./logger').logger

log.use(app);

app.use(compress())
app.use(express.static("../opt"))

app.use(express.static("dist"))
app.use(express.static("dist2"))
app.use(express.static("dist-cache"))
app.use(express.static("public"))
app.use(express.static("devDocument"))//专门存放开放相关文档
app.use(express.static("models"))//模版
app.use(express.static("sales"))//销售相关文档
app.use(express.static("productDelivery"))//产品交付相关文档
app.use(express.static("afterSales"))//售后服务相关文档
app.use(express.static("uploads"));
app.use(bodyParser.json({limit: '50mb'})); // for parsing application/json
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
app.use(cookieParser());

//路由模块化
app.use('/admin',admin); 

var server = app.listen(2233, async function () {
  logger.info("最大配置内存为"+require("v8").getHeapStatistics().total_available_size / 1024 / 1024)
  //内存监控监控
   var memhealth=setInterval(() => {
      var  mem = process.memoryUsage();
      if(mem.heapUsed/1024/1024>1000){
        sendemailtoadmin("内存应用监控提醒："+JSON.stringify(mem)+" 上报时间未--"+new Date())
        clearInterval(memhealth)
      }
    }, 2000)
})